﻿Imports Microsoft.TeamFoundation.Client
Imports Microsoft.TeamFoundation.WorkItemTracking.Client
Imports System.Management.Automation

<Cmdlet(VerbsCommon.Get, TeamSystemNouns.WorkItem)> _
Public Class GetWorkItemCmdlet
    Inherits TeamFoundationServerCmdletBase

    Public Sub New()
    End Sub

    Private _id As Integer

    <Parameter(Position:=1, Mandatory:=True, ValueFromPipelineByPropertyName:=True), ValidateRange(1, Integer.MaxValue)> _
    Public Property Id() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Private _revision As Integer

    <Parameter(Position:=2, ValueFromPipelineByPropertyName:=True), ValidateRange(1, Integer.MaxValue)> _
    Public Property Revision() As Integer
        Get
            Return _revision
        End Get
        Set(ByVal value As Integer)
            _revision = value
        End Set
    End Property

    Protected Overrides Sub ProcessRecord()
        If Revision = 0 Then
            WriteObject(WorkItemStore.GetWorkItem(Id))
        Else
            WriteObject(WorkItemStore.GetWorkItem(Id, Revision))
        End If
    End Sub
End Class
